package com.zxl.chatroomserver;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

public class AcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel, AsyncServerHandler> {
    @Override
    public void completed(AsynchronousSocketChannel result, AsyncServerHandler attachment) {
        attachment.getServerSocketChannel().accept(attachment,this);
        ByteBuffer byteBuffer=ByteBuffer.allocate(1024);
        result.read(byteBuffer,byteBuffer,new ReadComplationHandler(result));
    }

    @Override
    public void failed(Throwable exc, AsyncServerHandler attachment) {
        exc.printStackTrace();
        attachment.getLatch().countDown();
    }
}
